<?php
include_once 'checkLogin.php';
include_once 'conn.php';
$carID = $_GET['carID'];
$sql1 = "update carinfo set carNum = carNum + 1 where id = $carID";
$sql2 = "insert into votedetail (userID, carID, voteTime, ip) VALUES ('".$_SESSION['loggedUserID']."','$carID','".time()."','')";
mysqli_autocommit($conn,0);//取消自动提交
$result1 = mysqli_query($conn,$sql1);
$result2 = mysqli_query($conn,$sql2);
if($result2 and $result1){
    mysqli_commit($conn);
    echo "<script>alert('投票成功');location.href='index.php';</script>";
}
else{
    mysqli_rollback($conn);
    echo "<script>alert('投票失败');history.back();</script>";
}
